package swimming;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;


public class DBUtils {
    public static Connection getConnection() throws SQLException{
        String url="jdbc:mysql://localhost:3306/swimming?characterEncoding=utf8&serverTimezone=Asia/Shanghai";
        String user="root";
        String password="123456";
        Connection conn= DriverManager.getConnection(url,user,password);
        return conn;
    }
    public static void close(Connection conn,Statement stat,ResultSet rs) throws SQLException {
        if(rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw e;
            }
        }
        if(stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw e;
            }
        }
        if(conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw e;
            }
        }
    }
}
